home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 2 / MacMania 2.toast / Demo's / Tools&Utilities / System Utilities / AV Resource Manager Tuner 1.0 / RMgrPatch.a < prev   
Encoding:
Text File  |  1993-11-11  |  4.9 KB  |  105 lines  |  [TEXT/MPS ]

  1. ;
  2. ;    File:        SMResourceManagerPatch.a
  3. ;
  4. ;    Written by:    Steve Kiene
  5. ;
  6. ;    Change History (most recent first):
  7. ;
  8. ;      <1>    11/11/93    skk        Initial version.
  9.  
  10. **********************************************************************************************************
  11. *                                                                                                        *
  12. * SuperMario Resource Manager patcher, written by Steve Kiene                                            *
  13. *                                                                                                        *
  14. * Background: With the advent of the SuperMario ROMs (AV class machines), Apple made a change to the     *
  15. * Resource Manager to try and prevent damaged resource files. The change was to always flush a resource  *
  16. * file whenever the end-of-file changed. This occurs as a result of the following traps: _UpdateResFile, *
  17. * _ChangedResource, _AddResource, _SetResInfo, and _RmveResource.                                        *
  18. * This change does seem to help prevent damaged resource files, but it was a side-effect of causing      *
  19. * many operations on resource files to slow down considerably.                                           *
  20. *                                                                                                        *
  21. * I have written a little piece of code to prevent the resource file from being flushed by the Resource  *
  22. * Manager. While this will provide a speedup of some operations, it removes the safety that was added    *
  23. * by Apple. If you crash while performing a resource operation, you are just as likely to suffer a       *
  24. * damaged resource file as with pre-SuperMario ROMs. If safety is a concern, then this patch is not      *
  25. * something for you to use. If speed is your main concern, then this is the patch for you.               *
  26. *                                                                                                        *
  27. * The patch looks back on the stack to see if the Resource Manager is the one who called _FlushFile.     *
  28. * If so, it returns without calling _FlushFile. If someone else called, _FlushFile is called.            *
  29. * It determines if the Resource Manager called by looking at the return address on the stack, which is   *
  30. * stored at sp+28 (+28 because the trap dispatcher saves various registers on the stack before calling   *
  31. * the trap. Once we have the return address, we look 10 bytes back and compare 12 bytes to see if it     *
  32. * is the code of the subroutine that the Resource Manager uses to flush the cache.                       *
  33. * If someone has tail patched _FlushFile, this patch will not be effective.                              *
  34. *                                                                                                        *
  35. * I have placed this code in the public domain. Anyone may use this as they wish. However, I take no     *
  36. * responsibility and offer no warranties for this code. If it doesn't work for you, I'm sorry. If it     *
  37. * works for you, then I hope you find it useful.                                                         *
  38. *                                                                                                        *
  39. * Written by Steve Kiene, MindVision Software  P.O. Box 81886 Lincoln, NE 68501                          *
  40. * AppleLink, AOL: MINDVISION                                                                             *
  41. * CIS: 70253,1437                                                                                        *
  42. *                                                                                                        *
  43. **********************************************************************************************************
  44.  
  45.  
  46. ; Build Commands
  47.  
  48. ; asm RMgrPatch.a
  49. ; link RMgrPatch.a.o -rt INIT=1001 -rn -ra =resSysheap -t INIT -c MV15 ∂
  50. ; -o 'a:systemƒ:extensions:AV Resource Manager Tuner'
  51.  
  52.  
  53.  
  54.     include 'Traps.a'
  55.     include 'SysEqu.a'
  56.     
  57.     MACHINE MC68040
  58.     
  59. _CacheFlush        OPWORD    $a0bd
  60.  
  61. MAIN    PROC
  62.     
  63.     cmp.b    #$04,CPUFlag                    ; is this an 040 (i.e. _might_ this patch be useful)
  64.     blt.s    @exit                            ; exit if not
  65.     
  66.     move.l    a0,-(sp)                        ; resource handle is already in a0
  67.     _DetachResource
  68.     
  69.     move    #$a045,d0                        ; _FlushFile trap
  70.     _GetTrapAddress
  71.     IMPORT    MyAddr
  72.     lea        MyAddr+2,a1
  73.     move.l    a0,(a1)                            ; store original _FlushFile trap address
  74.     _CacheFlush                                ; to write out the original trap address
  75.     
  76.     move    #$a045,d0                        ; _FlushFile trap
  77.     IMPORT    MyPatch
  78.     lea        MyPatch,a0
  79.     _SetTrapAddress                            ; set _FlushFile to our code
  80.  
  81. @exit
  82.     rts
  83. ENDP
  84.     
  85.  
  86. MyPatch    PROC    EXPORT
  87.     
  88.     cmp.l    #$009266ae,([28,sp],-10)        ; look back at who called _FlushFile. See if we recognize
  89.     bne.s    @out                            ; the code. If these 12 bytes match, then we won't call
  90.     cmp.l    #$6100ff66,([28,sp],-6)            ; the original _FlushFile.
  91.     bne.s    @out
  92.     cmp.l    #$a04560a2,([28,sp],-2)
  93.     bne.s    @out
  94.     
  95.     clr        d0                                ; return a result of noErr
  96.     rts
  97.  
  98. @out
  99.     EXPORT    MyAddr
  100. MyAddr
  101.     jmp        $80000000                        ; call the original _FlushFile trap
  102. ENDP
  103.  
  104.     END
  105.